package me.numark.view;

import android.support.v4.app.Fragment;
import android.view.View;

import com.marshalchen.ultimaterecyclerview.UltimateRecyclerviewViewHolder;

import me.numark.activities.BaseActivity;
import me.numark.fragments.AskLoginFragment;
import me.numark.utils.Global;

/**
 * Created by Evan on 15/7/27.
 */
public class BaseViewHolder extends UltimateRecyclerviewViewHolder implements View.OnClickListener {

    protected BaseActivity mActivity;
    protected Fragment mFragment;
    public View mView;

    public BaseViewHolder(View itemView) {
        super(itemView);
        mView = itemView;
    }

    public BaseViewHolder(View itemView, Object parent) {
        super(itemView);
        if (parent == null)
            return;
        if (parent instanceof BaseActivity) {
            mActivity = (BaseActivity) parent;
        } else if (parent instanceof Fragment) {
            mFragment = (Fragment) parent;
        }
    }

    public void addOnClickListener(View view) {
        if (view != null)
            view.setOnClickListener(this);
    }

    protected boolean checkLogin() {
        if (Global.isLoggedIn()) {
            return true;
        }
        if (mActivity != null)
            AskLoginFragment.show(mActivity);
        else if (mFragment != null)
            AskLoginFragment.show(mFragment);
        return false;
    }

    @Override
    public void onClick(View v) {

    }
}
